﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using DTO;
using DAO;
namespace Banking.Nhân_viên
{
    public partial class ThongTinCaNhan : UserControl
    {
        private NhanVien nv;
        public ThongTinCaNhan()
        {
            InitializeComponent();
        }

        public void init(int ma)
        {

            List<TruSo> lstTruSo = TruSoDA.GetALl(0);
            cbbTruSo.DataSource = lstTruSo;
            cbbTruSo.DisplayMember = "Ten";
            cbbTruSo.ValueMember = "MaTruSo";
            List<GioiTinh> lstGioiTinh = GioiTinhDAO.GetALL();
            cbbGioiTinh.DataSource = lstGioiTinh;
            cbbGioiTinh.DisplayMember = "MoTa";
            cbbGioiTinh.ValueMember = "MaLoaiGioiTinh";

            nv = NhanVienDAO.GetByMaDangNhap(ma);
            BuildBinding();

        }

        private void BuildBinding()
        {
            if (nv != null)
            {
                txtHoTen.DataBindings.Add("Text", nv, "TenNV");
                txtCMND.DataBindings.Add("Text", nv, "CMND");
                txtDiaChi.DataBindings.Add("Text", nv, "DiaChi");
                dataNgaySinh.DataBindings.Add("Value", nv, "NgaySinh");
                txtMoTa.DataBindings.Add("Text", nv, "MoTa");
                txtMa.DataBindings.Add("Text", nv, "MaNV");
                txtDienThoai.DataBindings.Add("Text", nv, "DienThoai");
                cbbGioiTinh.DataBindings.Add("SelectedText", nv, "GioiTinh");
                cbbTruSo.DataBindings.Add("SelectedValue", nv, "MaTruSo");
                //cbbGioiTinh.DataBindings.Add("SelectedValue", nv, "MaLoaiGioiTinh");
            }
            
        }


        private void btnUpDrityRead_Click(object sender, EventArgs e)
        {
            if (txtHoTen.Text == "" || txtDiaChi.Text == "" || txtCMND.Text == "")
            {
                MessageBox.Show("Bạn phải cung cấp họ tên , cmnd, địa chỉ");
            }
            nv.TenNV = txtHoTen.Text;
            nv.DiaChi = txtDiaChi.Text;
            nv.CMND =Convert.ToInt32( txtCMND.Text);
            nv.DienThoai =Convert.ToInt32(txtDienThoai.Text);
            nv.NgaySinh = Convert.ToDateTime(dataNgaySinh.Text);
            nv.MoTa = txtMoTa.Text;
            nv.MaLoaiGioiTinh = cbbGioiTinh.SelectedIndex;
            nv.MaTruSo = cbbGioiTinh.SelectedIndex;


            //string ten = cbbTruSo.SelectedValue.ToString();
            //int ma = TruSoDA.GetByTen(ten);
            //nv.MaTruSo = ma;
            //ten = cbbGioiTinh.SelectedValue.ToString();
            //ma = GioiTinhDAO.GetByTen(ten);
            //nv.MaLoaiGioiTinh = ma;
            NhanVienDAO.CapNhatThongTinNhanVienDirtyRead(nv);
            MessageBox.Show("Cập nhật thông tin thành công ", "BankingSystem", MessageBoxButtons.OK, MessageBoxIcon.Question);

        }

        private void buttonX1_Click(object sender, EventArgs e)
        {

        }
     


       
    }
}
